<template>
  <div class="wage-set-rule-detail-wrapper page-miH page-bgBack">
    <a-row class="head">
      <div style="cursor:pointer">
        <a-icon type="left" @click="goDetail" />
        <div class="left2" @click="goDetail">返回</div>
      </div>
      <a-col class="title">
        <strong>修改计税规则</strong>
      </a-col>
    </a-row>
    <div class="rule-item-wrapper">
      <div class="rule-item">
        <span class="rule-item-title">方案名称</span>
        <span class="rule-item-value">{{ dataDetail.name }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">个税类型</span>
        <span class="rule-item-value">{{ taxRule[dataDetail.type - 1] }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">描述</span>
        <span class="rule-item-value">{{ dataDetail.description }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">计税周期</span>
        <span class="rule-item-value">
          <span>
            <span
              :class="selected === 1 ? 'rule-circle-item circle-primary' : 'rule-circle-item'"
              style="margin-right: 15px;"
              @click="selected = 1"
            >
              <span class="rule-circle-item-title ">上年12月到今年11月</span>
              <span class="rule-circle-item-text">
                对应的工资发放方式为次月发上月的工资
              </span>
            </span>
            <span :class="selected === 2 ? 'rule-circle-item circle-primary' : 'rule-circle-item'" @click="selected = 2">
              <span class="rule-circle-item-title">今年1月到12月</span>
              <span class="rule-circle-item-text">
                对应的工资发放方式为当月发当月的工资
              </span>
            </span>
          </span>
          <div class="rule-circle-tip">
            提示：工资发放方式将影响计税周期和报税
            <span class="rule-circle-detail" @click="toDetail">了解详情</span>
          </div>
        </span>
      </div>
      <div class="rule-item" v-if="selected === 1" style="display:flex;align-items:center;">
        <span class="rule-item-title">员工入职当月基本减除费用</span>
        <span class="rule-item-value">
          <a-radio-group v-model="deduction">
            <a-radio :value="1">
              10000元
            </a-radio>
            <a-radio :value="2">
              5000元
            </a-radio>
          </a-radio-group>
        </span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">是否计税</span>
        <span class="rule-item-value">{{ dataDetail.isCalculate ? "是" : "否" }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">起征点</span>
        <span class="rule-item-value">{{ dataDetail.threshold === 0 ? "-" : `${dataDetail.threshold}/月` }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title">个税结果</span>
        <span class="rule-item-value">{{ dataDetail.type === 3 ? "-" : dataDetail.taxResult }}</span>
      </div>
      <div class="rule-item">
        <span class="rule-item-title"></span>
        <span>
          <a-button type="primary" @click="saveRule">保存</a-button>
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import { getdetail, editRule } from "@/api/wages/set";
const taxRule = ["工资薪金所得", "劳动报酬所得", "不计税"];
export default {
  data() {
    return {
      dataDetail: {},
      taxRule,
      deduction: 1,
      selected: 1,
      companyId: "",
      taxRuleId: "",
      options: []
    };
  },

  created() {
    this.companyId = this.$store.state.hr.companyId;
    this.init();
  },

  methods: {
    goDetail() {
      this.$router.push({
        path: "/wages/set",
        query: {
          tabs: "1"
        }
      });
    },
    toDetail() {
      window.open("https://www.yuque.com/docs/share/b7da4e77-4ba1-40e1-8622-d5e4206ed877?# 《2019年最新税制》");
    },
    init() {
      this.taxRuleId = this.$route.query.taxRuleId;
      getdetail(this.taxRuleId)
        .then(res => {
          this.dataDetail = res.data;
          this.deduction = res.data.deduction;
          this.selected = res.data.taxCycle;
        })
        .catch(err => {
          console.log("debug log --> ", err);
        });
    },
    saveRule() {
      const data = {
        companyId: this.companyId,
        deduction: this.deduction,
        taxCycle: this.selected,
        id: this.taxRuleId
      };
      if (this.selected === 2) {
        delete data.deduction;
      }
      editRule(data)
        .then(res => {
          this.$router.push({
            path: "/wages/set"
          });
        })
        .catch(err => {
          console.log("debug log --> ", err);
        });
    }
  }
};
</script>

<style scoped lang="scss">
.wage-set-rule-detail-wrapper {
  .head {
    .anticon-left {
      z-index: 3;
      left: 27px;
      position: absolute;
      color: #d8d8d8;
      font-size: 20px;
      margin-top: 21px;
    }
    .left2 {
      z-index: 3;
      left: 50px;
      position: absolute;
      color: #595959;
      font-size: 16px;
    }
    font-size: 16px;
    color: #000;
    font-weight: 500;
    text-align: center;
    line-height: 60px;
    height: 60px;
    border-bottom: 1px solid #e8e8e8;
  }
  .rule-item-wrapper {
    margin-top: 40px;
    .rule-item {
      margin-bottom: 20px;
      margin-left: 50px;
      .rule-item-title {
        font-size: 14px;
        color: #7b7b7b;
        margin-right: 80px;
        width: 80px;
        display: inline-block;
      }
      .rule-item-value {
        font-size: 14px;
        color: #252525;
      }
    }

    .rule-circle-item {
      cursor: pointer;
      width: 178px;
      height: 108px;
      border-radius: 5px;
      display: inline-block;
      border: 1px solid #d8d8d8;
      padding: 20px;
      .rile-circle-item-title {
        font-size: 16px;
        color: #252525;
        display: inline-block;
      }
      .rule-circle-item-text {
        font-size: 12px;
        color: #595959;
        display: inline-block;
        margin-top: 10px;
      }
    }
    .rule-circle-tip {
      color: #999;
      font-size: 12px;
      margin-left: 160px;
      margin-top: 10px;
    }
    .rule-circle-detail {
      color: var(--primary);
      font-size: 12px;
      cursor: pointer;
    }

    .circle-primary {
      color: var(--primary);
      border: 1px solid var(--primary);
      .rile-circle-item-title {
        font-size: 16px;
        color: var(--primary);
        display: inline-block;
      }
      .rule-circle-item-text {
        font-size: 12px;
        color: var(--primary);
        display: inline-block;
        margin-top: 10px;
      }
    }
  }
}
</style>
